diff options
| author | secondl1ght <[email protected]> | 2022-08-22 18:00:00 -0400 |
|---|---|---|
| committer | secondl1ght <[email protected]> | 2022-08-22 18:00:00 -0400 |
| commit | 2aa7156e12200798c45a53878dbcc37c77625752 (patch) | |
| tree | 85d0cb70ec847bb7df8ca08ee5f5328ebc2600f4 /src/routes/[username] | |
| parent | bc77cf10532a4060d97b0f804111b4f582151120 (diff) | |
| download | coinos-ui-2aa7156e12200798c45a53878dbcc37c77625752.tar.gz coinos-ui-2aa7156e12200798c45a53878dbcc37c77625752.zip | |
finish hooking up currency selection
Diffstat (limited to 'src/routes/[username]')
| -rw-r--r-- | src/routes/[username]/+page.server.js | 2 | ||||
| -rw-r--r-- | src/routes/[username]/dashboard/+page.svelte | 22 | ||||
| -rw-r--r-- | src/routes/[username]/receive/+page.svelte | 61 | ||||
| -rw-r--r-- | src/routes/[username]/transactions/+page.svelte | 2 |
4 files changed, 55 insertions, 32 deletions
diff --git a/src/routes/[username]/+page.server.js b/src/routes/[username]/+page.server.js index 2520b0b1..9ae4af2d 100644 --- a/src/routes/[username]/+page.server.js +++ b/src/routes/[username]/+page.server.js @@ -18,5 +18,5 @@ export async function PUT({ request }) { let { token } = cookie.parse(request.headers.get('cookie') || ''); let { user } = await request.json(); await post(`/user`, user, { authorization: `Bearer ${token}` }); - console.log("put done") + console.log('put done'); } diff --git a/src/routes/[username]/dashboard/+page.svelte b/src/routes/[username]/dashboard/+page.svelte index 9e09aa16..56aa0d6f 100644 --- a/src/routes/[username]/dashboard/+page.svelte +++ b/src/routes/[username]/dashboard/+page.svelte @@ -2,7 +2,7 @@ import { post, failure } from '$lib/utils'; import { tick } from 'svelte'; import { AppHeader, Icon } from '$comp'; - import { rate, user, preferredCurrency } from '$lib/store'; + import { selectedRate, user } from '$lib/store'; import { _ } from 'svelte-i18n'; let payreq = '', @@ -26,24 +26,19 @@ $: btcPrice = new Intl.NumberFormat('en-US', { style: 'currency', - currency: 'USD' - }).format($rate); + currency: $user.currency + }).format($selectedRate); $: accountBalanceFiat = new Intl.NumberFormat('en-US', { style: 'currency', - currency: 'USD' - }).format($user.account.balance * ($rate / 100000000)); + currency: $user.currency + }).format($user.account.balance * ($selectedRate / 100000000)); $: accountBalanceBtc = $user.account.balance / 100000000; $: accountBalanceSats = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format( $user.account.balance ); - - $: feepayreq = new Intl.NumberFormat('en-US', { - style: 'currency', - currency: 'USD' - }).format(($user.account.balance * ($rate / 100000000)) / 100); </script> {#if $user} @@ -64,8 +59,9 @@ {#if !withdrawing} <span class="text-secondary mx-auto text-lg font-bold" >{$_('user.dashboard.bitcoinPrice')} - <span class="text-black">{$rate ? btcPrice : $_('user.dashboard.fetchingRate')}</span> - {$preferredCurrency} + <span class="text-black" + >{$selectedRate ? btcPrice : $_('user.dashboard.fetchingRate')}</span + > </span> <span class="text-secondary block mt-1">{@html $_('user.dashboard.dataFromBinance')} </span> @@ -75,7 +71,7 @@ </h3> <span class="text-3xl font-bold block mb-1" - >{$rate ? accountBalanceFiat : $_('user.dashboard.fetchingRate')}</span + >{$selectedRate ? accountBalanceFiat : $_('user.dashboard.fetchingRate')}</span > <span class="text-secondary text-xl block">{accountBalanceSats} SAT</span> diff --git a/src/routes/[username]/receive/+page.svelte b/src/routes/[username]/receive/+page.svelte index 6d750d1b..2706ec86 100644 --- a/src/routes/[username]/receive/+page.svelte +++ b/src/routes/[username]/receive/+page.svelte @@ -2,7 +2,7 @@ // in the future we will want to allow users to set their fiat currency in the settings import { AppHeader, Icon } from '$comp'; import { goto } from '$app/navigation'; - import { invoiceAmount, invoiceAmountFiat, rate, user } from '$lib/store'; + import { invoiceAmount, invoiceAmountFiat, selectedRate, user } from '$lib/store'; import { post, warning } from '$lib/utils'; import { page } from '$app/stores'; import { _, number } from 'svelte-i18n'; @@ -11,11 +11,13 @@ let amountFiat = 0; let amountSats = 0; - $: amount = useFiat ? Math.round(amountFiat / ($rate / 100000000)) : amountSats; + $: amount = useFiat ? Math.round(amountFiat / ($selectedRate / 100000000)) : amountSats; - $: $invoiceAmount = parseInt(amountSats === 0 ? amountFiat / ($rate / 100000000) : amountSats); + $: $invoiceAmount = parseInt( + amountSats === 0 ? amountFiat / ($selectedRate / 100000000) : amountSats + ); $: $invoiceAmountFiat = parseInt( - amountFiat === 0 ? amountSats * ($rate / 100000000) : amountFiat + amountFiat === 0 ? amountSats * ($selectedRate / 100000000) : amountFiat ); $: amountSatsFormatted = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format( amountSats @@ -23,11 +25,11 @@ $: amountFiatConverted = new Intl.NumberFormat('en-US', { style: 'currency', - currency: 'USD' - }).format(amountSats * ($rate / 100000000)); + currency: $user.currency + }).format(amountSats * ($selectedRate / 100000000)); $: amountSatsConverted = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format( - amountFiat / ($rate / 100000000) + amountFiat / ($selectedRate / 100000000) ); const numPad = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', '<']; @@ -50,7 +52,7 @@ amountSats = 0; } } - } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > $rate) { + } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > $selectedRate) { warning($_('user.receive.lessThan1BTCWarning')); } else if (amountFiat !== 0 && amountFiat.match(/\.../)) { return; @@ -60,7 +62,7 @@ } else { if (value === '.') { return; - } else if (amountSats === 0 && value !== '<' && value !== '0') { + } else if (amountSats === '0' && value !== '<' && value !== '0') { amountSats = value; } else if (value === '<') { if (amountSats !== 0) { @@ -79,7 +81,11 @@ }; let submit = async () => { - let { id } = await post('/invoice', { amount, rate: $rate, username: $page.params.username }); + let { id } = await post('/invoice', { + amount, + rate: $selectedRate, + username: $page.params.username + }); goto(`/invoice/${id}`); }; </script> @@ -88,26 +94,47 @@ <AppHeader /> <div class="flex justify-center items-center mt-20 mb-3 px-3"> - {#if $rate} + {#if $selectedRate} <div class="space-y-5"> <!-- amounts --> <div class="text-center"> <div class="text-5xl md:text-6xl font-semibold tracking-widest mb-1"> - {useFiat ? `$${amountFiat}` : amountSatsFormatted}<span - class="tracking-normal text-base font-normal">{useFiat ? 'USD' : 'SAT'}</span + {useFiat + ? `${ + $user.currency === 'USD' || + $user.currency === 'CAD' || + $user.currency === 'AUD' || + $user.currency === 'NZD' || + $user.currency === 'MXN' || + $user.currency === 'BRL' || + $user.currency === 'HKD' || + $user.currency === 'TWD' + ? '$' + : $user.currency === 'JPY' || $user.currency === 'CNY' + ? '¥' + : $user.currency === 'GBP' + ? '£' + : $user.currency === 'EUR' + ? '€' + : $user.currency === 'KRW' + ? '₩' + : '' + }${amountFiat}` + : amountSatsFormatted}<span class="tracking-normal text-base font-normal" + >{useFiat ? $user.currency : 'SAT'}</span > </div> <span class="text-secondary mr-1" - >{useFiat ? `${amountSatsConverted} SAT` : `${amountFiatConverted} USD`}</span + >{useFiat ? `${amountSatsConverted} SAT` : amountFiatConverted}</span > <button on:click={() => { if (useFiat) { - amountSats = (amountFiat / ($rate / 100000000)).toFixed(0).toString(); + amountSats = (amountFiat / ($selectedRate / 100000000)).toFixed(0).toString(); } else { amountFiat = - (amountSats * ($rate / 100000000)).toFixed(2) > 0.0 - ? (amountSats * ($rate / 100000000)).toFixed(2).toString() + (amountSats * ($selectedRate / 100000000)).toFixed(2) > 0.0 + ? (amountSats * ($selectedRate / 100000000)).toFixed(2).toString() : 0; } useFiat = !useFiat; diff --git a/src/routes/[username]/transactions/+page.svelte b/src/routes/[username]/transactions/+page.svelte index 1cc2611a..996b9b9a 100644 --- a/src/routes/[username]/transactions/+page.svelte +++ b/src/routes/[username]/transactions/+page.svelte @@ -31,7 +31,7 @@ <span class="block mb-1" >{tx.amount > 0 ? '+' : ''}{new Intl.NumberFormat('en-US', { style: 'currency', - currency: 'USD' + currency: tx.currency }).format(tx.amount * (tx.rate / 100000000))} </span> |
